# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Figure SI1 (Average percent of women running for and elected to office in the municipalities of the canton of Zurich, with the percent of women in the Swiss national parliament and the average percent of women in the executives of Swiss municipalities)
# gilardi@ipz.uzh.ch, 2014-06-24

# Set working directory
setwd("../Data/")

# Load data
d <- read.csv("dataset-full.csv")
ch <- read.csv("women-municip-ch.csv")
w <- read.csv("women-parl.csv")

# Vector of election years
yr <- seq(1970, 2010, 4)

# Compute and store means
m.elec <- m.cand <- c()
for(i in 1:length(yr)){
	m.cand[i] <- mean(d$pcent.women.cand[d$year==yr[i]], na.rm=T)*100
	m.elec[i] <- mean(d$pcent.women.elected[d$year==yr[i]], na.rm=T)*100
}


# Compute percentage
tot <- 246
w$pcentw <- 100*(w$nr + w$sr)/tot


# Figure

#pdf(file="Figure-SI1.pdf", paper="special", width=7.5, height=5.5)
par(mar=c(3.5,3.5,2,1), mgp=c(2.5,0.8,0), cex.axis=1.2, cex.lab=1.2, font.main=1)
plot(range(c(yr, ch$yr, w$yr)), range(c(m.cand, m.elec, ch$pcentw, w$pcentw)), type="n", axes=F, ylab="Percent of women", xlab="")
axis(1, at=yr)
axis(2)
lines(yr, m.cand, type="b", pch=19, cex=1.3)
lines(yr, m.elec, type="b", pch=1, cex=1.3)
lines(w$yr, w$pcentw, lty=2)
lines(ch$yr, ch$pcentw, lty=2)
legend("bottomright", pch=c(19,1), c("Running for office in municipalities in Zurich", "Elected to office in municipalities in Zurich"), cex=1.1, bty="n")
text(1973, 8.5, "National\nparliament")
text(2000, 15, "Municipalities\n(Swiss average)")
#dev.off()

